//
//  InputCryptKeyController.m
//  iLiteNote
//
//  Created by xiangbc on 16/4/7.
//  Copyright © 2016年 LiteNice. All rights reserved.
//

#import "InputCryptKeyController.h"
#import "WebViewController.h"
#import "TextViewController.h"

@interface InputCryptKeyController () {
    NSString *_notepath;
    WebViewController *_webCtrl;
    //UITextView *_textView;
    UITextField *_textField;
}

@end

@implementation InputCryptKeyController

- (id) initWithPath:(NSString*)notepath withWeb:(WebViewController*)webCtrl
{
    self = [super self];
    
    if (self) {
        _notepath = notepath;
        _webCtrl = webCtrl;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    CGRect frame = [[UIScreen mainScreen]bounds];
    _textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 30, frame.size.width, 30)];
    [_textField.layer setBorderColor:[[[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0] colorWithAlphaComponent:1] CGColor]];
    [_textField.layer setBorderWidth:1.0];
    //_textField.layer.cornerRadius = 3;
    _textField.clipsToBounds = YES;
    _textField.secureTextEntry = YES;
    _textField.placeholder = @"请输入vim crypt密码";
    _textField.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_textField];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(0, 0, 40, 30);
    [btn setTitle:@"go" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(goTouch:) forControlEvents:UIControlEventTouchUpInside];
    
    UINavigationItem *navItem = self.navigationItem;
    [navItem setTitle:@"vim 密码"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:btn];
    navItem.rightBarButtonItem = item;
    
    self.view.backgroundColor = [UIColor colorWithRed:0.96 green:0.96 blue:0.96 alpha:1];
    //self.view.backgroundColor = [UIColor redColor];
    NSArray * arr = [self.view subviews];
    NSLog(@"%d", (int)arr.count);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)goTouch:(id)sender {
    NSLog(@"go");
    UINavigationController *n = self.navigationController;
    [self.navigationController popViewControllerAnimated:NO];
    
    TextViewController *txtVc = [[TextViewController alloc]init:_notepath];
    txtVc.cryptKey = _textField.text;
    txtVc.refreshBlock = ^{
        //[_webCtrl refreshWebView];
    };
    [n pushViewController:txtVc animated:NO];
}

@end
